<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>配送员管理</title>
	<meta name="decorator" content="default"/>
	<script>
		var isok=1;
		$(function(){
			$("#mobile").blur(function(){
				var mobile=$("#mobile").val();
				var mid=$("#mid").val();
				if(mobile==""){
					var tt=document.getElementById("tt");
					tt.innerHTML="请填写手机号！";
				}else{
					$.ajax({
						type : "POST",
						url : "${ctx}/sys/tbSender/checkSenderByMobile",
						data : {
							mobile:mobile,
							id:mid
						},
						success : function(data) {
							if(data=="false"){
								document.getElementById("tt").innerHTML="手机号已经存在！";
								isok=2;
							}else{
								document.getElementById("tt").innerHTML="*";
								isok=1;
							}
						}
					});
				}

			});
		});

	</script>
	<script type="text/javascript">
		function passwordLevel(password) {
			var Modes = 0;
			for (i = 0; i < password.length; i++) {
				Modes |= CharMode(password.charCodeAt(i));
			}
			return bitTotal(Modes);
			//CharMode函数
			function CharMode(iN) {
				if (iN >= 48 && iN <= 57)//数字
					return 1;
				if (iN >= 65 && iN <= 90) //大写字母
					return 2;
				if ((iN >= 97 && iN <= 122) || (iN >= 65 && iN <= 90))
				//大小写
					return 4;
				else
					return 8; //特殊字符
			}
			//bitTotal函数
			function bitTotal(num) {
				modes = 0;
				for (i = 0; i < 4; i++) {
					if (num & 1) modes++;
					num >>>= 1;
				}
				return modes;
			}
		}
		$(document).ready(function() {
			//$("#name").focus();
			$.validator.addMethod("strongPsw",function(value,element){
				if(passwordLevel(value)==1){
					return false;
				}else{
					return true
				}
			},"请输入数字+字母大小写混合密码");
			$("#inputForm").validate({
				rules: {
					password:{
						required:true, //必填
						minlength:6, //最小长度
						maxlength:32, //最大长度
						strongPsw:true, //密码强度
					},
					mobile:{
						required:true, //必填
						minlength:11, //最小长度
						maxlength:11, //最大长度
					}

				},
				submitHandler: function(form){
					if(isok!=2){
						loading('正在提交，请稍等...');
						form.submit();
					}else{
						document.getElementById("tt").innerHTML="手机号已经存在,请填写新的手机号！";
					}

				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/tbSender/">配送员列表</a></li>
		<li class="active"><a href="${ctx}/sys/tbSender/form?id=${tbSender.id}">配送员${not empty tbSender.id?'修改':'添加'}<shiro:lacksPermission name="sys:tbSender:edit"></shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tbSender" action="${ctx}/sys/tbSender/save" method="post" class="form-horizontal">
		<form:hidden path="id" id="mid"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">真实姓名：</label>
			<div class="controls">
				<form:input path="realName" htmlEscape="false" maxlength="50" class="required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">手机号：</label>
			<div class="controls">
				<form:input id="mobile" path="mobile" htmlEscape="false" maxlength="20" class="phone"/>
				<span class="help-inline"><font color="red" id="tt">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备用手机号：</label>
			<div class="controls">
				<form:input path="bakMobile" htmlEscape="false" maxlength="20" class="phone" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">密码：</label>
			<div class="controls">
				<form:input id="password" path="password" htmlEscape="false" maxlength="50" class="required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否启用：</label>
			<div class="controls">
				<c:choose>
				<c:when test="${tbSender.activeFlag eq '0'}">
					<form:radiobutton  path="activeFlag" value="0" checked="true" />启用
					<form:radiobutton  path="activeFlag" value="1" />禁用
				</c:when>
				<c:when test="${tbSender.activeFlag eq '1'}">
					<form:radiobutton  path="activeFlag" value="0" />启用
					<form:radiobutton  path="activeFlag" value="1" checked="true" />禁用
				</c:when>
					<c:otherwise>
						<form:radiobutton  path="activeFlag" value="0"  checked="true" />启用
						<form:radiobutton  path="activeFlag" value="1"  />禁用
					</c:otherwise>
				</c:choose>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">性别：</label>
			<div class="controls">
				<c:choose>
					<c:when test="${tbSender.sex eq '0'}">
						<form:radiobutton  path="sex" value="0" checked="true" />男
						<form:radiobutton  path="sex" value="1" />女
					</c:when>
					<c:when test="${tbSender.sex eq '1'}">
						<form:radiobutton  path="sex" value="0"  />男
						<form:radiobutton  path="sex" value="1" checked="true" />女
					</c:when>
					<c:otherwise>
						<form:radiobutton  path="sex" value="0" checked="true" />男
						<form:radiobutton  path="sex" value="1" />女
					</c:otherwise>
				</c:choose>

			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>